// eslint.config.mjs
import nuxtPlugin from '@nuxt/eslint-plugin'
import js from '@eslint/js'
import vueParser from 'vue-eslint-parser'
import tsParser from '@typescript-eslint/parser'
import tsPlugin from '@typescript-eslint/eslint-plugin'
import globals from 'globals'

export default [
  // 基础 JavaScript 配置
  {
    files: ['**/*.{js,jsx,cjs,mjs,ts,tsx,cts,mts,vue}'],
    languageOptions: {
      ecmaVersion: 'latest',
      sourceType: 'module',
      globals: {
        ...globals.browser,
        ...globals.node,
        ...globals.es2021
      },
      parser: vueParser,
      parserOptions: {
        parser: {
          ts: tsParser,
          js: tsParser,
          typescript: tsParser,
          '<template>': 'espree'
        },
        extraFileExtensions: ['.vue'],
        project: true
      }
    },
    plugins: {
      '@typescript-eslint': tsPlugin,
      '@nuxtjs': nuxtPlugin
    },
    rules: {
      ...js.configs.recommended.rules,
      ...tsPlugin.configs.recommended.rules,
      'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'warn',
      'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'warn',
      '@typescript-eslint/no-unused-vars': [
        'warn',
        { argsIgnorePattern: '^_', varsIgnorePattern: '^_' }
      ],
      '@typescript-eslint/consistent-type-imports': 'error'
    }
  },

  // Vue 文件特定配置
  {
    files: ['**/*.vue'],
    rules: {
      ...nuxtPlugin.configs.recommended.rules,
      'vue/multi-word-component-names': 'off',
      'vue/no-multiple-template-root': 'off',
      'vue/require-default-prop': 'off',
      'vue/html-self-closing': [
        'error',
        {
          html: {
            void: 'always',
            normal: 'always',
            component: 'always'
          }
        }
      ]
    }
  },

  // Nuxt 特定规则
  {
    files: [
      'nuxt.config.{js,ts}',
      'app.vue',
      'error.vue',
      'app/**/*.{js,ts,vue}',
      'components/**/*.{js,ts,vue}',
      'layouts/**/*.{js,ts,vue}',
      'pages/**/*.{js,ts,vue}',
      'plugins/**/*.{js,ts,vue}',
      'server/**/*.{js,ts}'
    ],
    rules: {
      ...nuxtPlugin.configs['nuxt-recommended'].rules,
      '@nuxtjs/no-use-moved-components': 'error',
      '@nuxtjs/require-nuxt-config': 'error'
    }
  },

  // 忽略文件配置
  {
    ignores: [
      '.nuxt/**',
      '.output/**',
      'dist/**',
      'node_modules/**',
      '**/*.d.ts',
      'nitro.config.ts',
      'postcss.config.js',
      'tailwind.config.js',
      'vite.config.ts'
    ]
  }
]
